<template>
<div>
  名字：<input type="text" v-model="from.name">
  用户名：<input type="text" v-model="from.username">
  密码：<input type="text" v-model="from.password">
  班级：<select name="" id="" v-model="from.cla">
          <option :value="i.id" v-for="i in list" >{{i.name}}</option>
      </select>
  <p><button @click="reg">注册</button></p>
</div>
</template>

<script>
export default {
  name: "stuReg",
  data(){
    return{
      from:{},
      list:[],
    }
  },
  methods:{
    reg(){
      this.$axios.post('users/reg/',this.from)
      .then(res=>{
        if(res.data.code==200){
          localStorage.setItem('id',res.data.id)
          localStorage.setItem('name',res.data.name)
          this.from={}
          alert('注册成功')
          this.$router.push('stu')
        }else {
          alert('注册失败')
        }
      })
    },
    get_class(){
      this.$axios.get('users/showCourse').then(res=>{
        if(res.data.code==200){
          this.list = res.data.list

        }
      })
    }
  },
  mounted() {
    this.get_class()
  }
}
</script>

<style scoped>

</style>
